<!--移动签批->公文详情->局内便函->index-->
<template>
  <view>
    <van-tabs color="#1989fa" title-active-color="#1989fa" animated swipeable @change="onChange">
      <van-tab title="公文详情" name="gwxq">
        <detail ref="detail" :proInstId="proInstId" :detailObj1="detailObj1" :otherDetail="otherDetail"
                @showCirculate="showCirculate" @showRevisionSheet="showRevisionSheet" @showFenfaSheet="showFenfaSheet"></detail>
      </van-tab>
      <van-tab title="版式稿纸" name="bsgz">
        <read :detailObj1="detailObj1" :proInstId="proInstId" :otherDetail="otherDetail"></read>
      </van-tab>
      <van-tab title="流转过程" name="lzgc" :key='2'>
        <docProcess :dataList="dataList"></docProcess>
      </van-tab>
    </van-tabs>
    <edit ref="edit" @refreshBtnGroup="refreshBtnGroup" :showEdit="showEdit" @closeEdit="closeEdit"></edit>
    <records @refreshBtnGroup="refreshBtnGroup" @saveOpinionAndSendWithoutSelectUser="saveOpinionAndSendWithoutSelectUser" :showRecords="showRecords" @closeRecords="closeRecords" :paramObject="paramObject"></records>
    <trans ref="trans" :proInstId="proInstId" @refreshBtnGroup="refreshBtnGroup" :showTrans="showTrans" @closeTrans="closeTrans" :paramObject="paramObject" :detailObject="detailObj1.detailObj"></trans>
    <send ref="send" @refreshBtnGroup="refreshBtnGroup" :showSend="showSend" @closeSend="closeSend" :paramObject="paramObject" :detailObject="detailObj1.detailObj"></send>
    <circulate ref="circulate" :showCircu="showCircu" :proInstId="proInstId" :title="circuTitle" @closeCirculate="closeCirculate"></circulate>
    <cy ref="cy" @refreshBtnGroup="refreshBtnGroup" :showCy="showCy" @closeCy="closeCy" :paramObject="paramObject" :gwTitle="circuTitle"></cy>
    <fb ref="fb" @refreshBtnGroup="refreshBtnGroup" :showFb="showFb" @closeFb="closeFb" :paramObject="paramObject" :gwTitle="circuTitle"></fb>
    <more :showShare="showShare" @closeShare="closeShare" :options="barList.slice(4)"></more>
    <revision ref="revision" :showRevision="showRevision" @closeRevisionSheet="closeRevisionSheet"></revision>
    <fenfa ref="fenfa" :showFenfa="showFenfa"  @closeFenfaSheet="closeFenfaSheet"></fenfa>
    <div style="height: 5rem;" v-if="fromType != 'search'">
      <van-tabbar v-model="active">
        <!-- <van-tabbar-item v-for="(item,index) in barList" v-if="index < 4" :name="item.name" :icon="item.icon" @click="onClick(item.name)">{{item.value}}
        </van-tabbar-item> -->
        <van-tabbar-item v-for="(item,index) in barList" :key="index" v-if="index < 4" :name="item.name" @click="onClick(item.operation)">
          <span>{{item.value}}</span>
          <template #icon="props">
            <img :src="props.active ? item.iconTab.active : item.iconTab.inactive" />
          </template>
        </van-tabbar-item>
      </van-tabbar>
    </div>
  </view>
</template>

<script>
import detail from 'pages/caac/components/jnbhDoc/compo-detail';
import docProcess from 'pages/caac/components/jnbhDoc/compo-process';
import read from 'pages/caac/components/jnbhDoc/compo-read';
import edit from 'pages/caac/components/jnbhDoc/compo-edit';
import records from 'pages/caac/components/common/compo-records';
import trans from 'pages/caac/components/jnbhDoc/compo-trans';
import more from 'pages/caac/components/jnbhDoc/compo-more';
import circulate from 'pages/caac/components/common/compo-circulate';
import cy from 'pages/caac/components/common/compo-cy';
import fb from 'pages/caac/components/common/compo-fbgl';
import send from 'pages/caac/components/jnbhDoc/compo-send';
import revision from 'pages/caac/components/common/compo-revision';
import fenfa from 'pages/caac/components/common/compo-fenfa';

export default {
  components: {
    detail,
    docProcess,
    edit,
    records,
    trans,
    more,
    read,
    circulate,
    cy,
    fb,
    send,
    revision,
    fenfa
  },
  onLoad: async function (option) {
    await this.$onLaunched //解決bug：执行完onLaunch后再执行页面onLoad

    this.userInfo = this.cache.get('userInfo')//从缓存获取用户信息
    //从地址栏获取proInstId
    this.proInstId = option.proInstId
    // console.log(proInstId);
    //fromType==search，说明是从公文搜索页跳转过来，隐藏相关操作按钮
    this.fromType = option.from
    if (this.proInstId != undefined && this.proInstId != '') {
      this.getCaacDetail(this.proInstId)//通过proInstId获取详情
      this.quertcirs(this.proInstId)//传阅情况
      this.findfbdept(this.proInstId)//司局分办处室
      this.getCaacOpinion(this.proInstId)//获取意见
    }
  },
  created() {

  },
  //文件编辑保存后返回到首页就重新获取文件及附件
  onShow(){
    //延迟调用，防止文件过大PC端没保存上就获取
    setTimeout(() => {
      if(this.util.isNotEmpty(this.extendIdForRelate)){
        this.getCaacBody(this.extendIdForRelate)//获取正文
        this.getCaacAttachment(this.extendIdForRelate)//获取附件
        this.getRelation(this.extendIdForRelate)//获取附加公文
      }
    }, 800)
  },
  data() {
    return {
      toActInstId:'',//退回便函拟稿人参数
      fromType:'',//fromType==search，说明是从公文搜索页跳转过来，隐藏相关操作按钮
      //记录对应的tab页数据是否已加载
      gwxqFlag:true,
      bsgzFlag:true,
      lzgcFlag:true,
      extendIdForRelate:'',
      userInfo:{},//当前登录用户信息，目前先从缓存中获取
      proInstId:'',
      fwId:'',//发文id
      active: '',
      showEdit: false,      // 修改公文要素
      showRecords: false,   // 填写意见
      showTrans: false,     // 流转
      showSend: false,      // 分送管理
      showShare: false,     // 更多
      barList: [],          // 功能按钮
      //公文详情
      detailObj1:{
        detailObj:null,//详情
        detailBody:null,//正文
        detailAttachment:null,//附件
        opinion:null,//意见
        optionBtn01:null,//获取签批功能菜单所需要的参数
        optionBtn02:null,//获取签批功能菜单所需要的参数
        optionBtn:null,//签批功能菜单,根据optionBtn01和optionBtn02返回的参数作为请求参数
      },
      dataList: {
        docProcess: {}, // 流转过程
        signProcess: [],// 会签件
        quertcirsProcess:[],//传阅人员
      },
      options:[],//更多操作
      //获取签批功能的接口里有
      paramObject:{
        //"bizId":"c7cbc671330d472b94fac967ba7b3840","proInstId":"55d46548585546c9a667796abf640713","configId":"68f6c3cf43aa466f899798691229159b","proDirId":"25ded9cc79b94329beffa78225a077c9","actInstId":"9af5da0ced204e36af9da9cd909394d5","actDefId":"nigao","workitemId":"5de39682f91d423b99b9a3f3e041d4e0","state":null,"isClosed":"2","configCode":"mhj_fw"
      },
      generateParamObject:{
        "fwId":'',
        "fwWord":'',
        "fwWordId":''
      },
      buttonArr:[],    // 要显示的功能按钮
      showCircu: false,   // 传阅详情
      circuTitle: '',     // 标题
      showCy: false,      // 传阅按钮
      showFb: false,      // 分办按钮
      otherDetail: {
        fbDeptList:[],// 已分办处室
        chuanYueList:[],//传阅情况
        nizhiDeptName: '',//拟制部门
        fsDataList:[],//呈送领导和分送部门
      },
      showRevision: false,//显示文档修订记录
      showFenfa: false,//分发组件
      opinionId:'',//需要删除的意见ID
    };
  },
  watch: {
  },

  mounted() {
    //处理页面弹出层初始化
    this.active = 'gwxq'
    this.showEdit = false
    this.showRecords = false
    this.showTrans = false
    this.showShare = false
  },
  methods: {
    //显示分发组件
    showFenfaSheet(){
      this.showFenfa = true
    },
    //关闭分发组件
    closeFenfaSheet(userInfo){
      //userInfo: {"userId":["2163","8943"],"userName":["刘xx","刘xx"]}
      this.$refs.detail.initParam(userInfo)
      this.showFenfa = false
    },
    //显示文档修订记录组件
    showRevisionSheet(proInstId) {
      this.showRevision = true
      this.$refs.revision.getDocumentRecordByProInstId(proInstId)
    },
    //关闭文档修订记录组件
    closeRevisionSheet() {
      this.showRevision = false
    },
    //tab 点击事件
    onChange(itemTitle){
      // this.$toast(itemTitle)
      if(itemTitle =='gwxq'){//公文详情
        if(this.gwxqFlag){
          this.getCaacDetail(this.proInstId)
        }
      }else if(itemTitle =='bsgz'){//版式稿纸
        if(this.bsgzFlag){
          //TODO 加载版式稿纸
        }
      }else if(itemTitle =='lzgc'){//流转过程
        if(this.lzgcFlag){
          this.getCaacDocProcess(this.proInstId)
          this.getListChildSubOperationLogs(this.proInstId)
        }
      }
    },
    //关闭修改公文要素
    closeEdit(showEdit){
      this.showEdit = false
    },
    //关闭填写意见
    closeRecords(showRecords){
      this.showRecords = false
    },
    //关闭流转
    closeTrans(showTrans){
      this.showTrans = false
    },
    //关闭更多操作
    closeShare(item){
      this.showShare = false
      this.btnFunction(item)
    },
    // 关闭分送配置
    closeSend(item) {
      this.showSend = false
    },
    //点击tabbar
    onClick(item){
      this.btnFunction(item)
    },
    //下边菜单点击功能
    btnFunction(item){
      //修改公文要素
      if(item == 'xggwys' || item == 'addElements'){
        this.showEdit = true
        this.$refs.edit.editGw(this.proInstId);//调用子组件的方法
      }
      //填写意见
      if(item == 'addReviews'){
        this.showRecords = true
      }
      //反馈意见
      if(item == 'addReviews_fk'){
        this.showRecords = true
      }
      //流转
      if(item == 'generalMove' || item == 'complete'){
        this.showTrans = true
        //调用子组件的方法
        this.$refs.trans.getSelectPerson(this.proInstId,this.detailObj1.detailObj.drafterId)
      }
      //传阅
      if(item == 'circulate'){
        this.showCy = true
        this.circuTitle = this.detailObj1.detailObj.title
      }
      //分办管理
      if(item == 'fbgl' || item == 'sendFb'){
        this.showFb = true
        this.circuTitle = this.detailObj1.detailObj.title
      }
      //分送管理
      if(item == 'distribute'){
        // this.$toast('分送管理')
        this.$refs.send.initAlreadyFs(this.proInstId)
        this.showSend = true
      }

      //更多操作
      if(item == 'more'){
        this.showShare = true
      }
      //结束公文
      if (item == 'js' || item == 'endProcess'){
        this.endProcess()
      }
      //会签管理
      if (item =='huiqianManagement'){
        //跳转到会签页面
        uni.navigateTo({
          url:"/pages/caac/submit/countersign?proInstId="+this.proInstId+"&fwId="+this.extendIdForRelate
        })
      }
      //办结并退秘书--走公文结束流程
      if(item == 'goOutProInst'){
        this.endAndTuimsConfirm()
      }
      //退回司局秘书
      if(item === 'goOutToSms' || item === 'goOutToMszz' || item === 'liuzhuanTuimishu' || item === 'szsliuzhuanTuimishu'){
        this.tuiGwmsConfirm(item)
      }

      //退回便函拟稿人分送
      if(item == 'sendback'){
        this.sendBackConfirm()
      }

      //作废
      if(item == 'cancelGw' || item == 'delForm'){
        this.cancelGwConfirm()
      }
      if(item == 'addElements_tongyi'){
        this.opinionType(item)//1-同意，2-已阅
      }
      if(item == 'addElements_yiyue_fs' || item == 'addElements_yiyue'){
        this.opinionType(item)//1-同意，2-已阅
      }
      //本单位会签完毕hqwb
      if(item == 'hqwb'){
        this.hqwbConfirm()
      }
      //清除意见
      if (item == 'deleteOpinion') {
        this.deleteOpinionConfirm()
      }

    },

    // 获取要显示的按钮
    async getButtonsData(proInstId){
      let _this = this
      await _this.$http({
        url: _this.$http.adornUrl(`/caac/oa/app/getButtonsData`),
        method: 'get',
        params: _this.$http.adornParams({
          'systemKey': _this.userInfo.systemKey,//固定值
          'systemFlag': _this.userInfo.systemFlag,//固定值
          'proInstId': proInstId
        })
      }).then(({data}) => {
        if(data.code == 200){
          this.buttonArr = data.data.buttons
        }
      })
    },

    // 关闭分办窗口
    closeFb() {
      this.showFb = false
    },
    // 关闭传阅窗口
    closeCy() {
      this.showCy = false
    },
    // 显示传阅详情
    showCirculate(val) {
      this.showCircu = true
      this.circuTitle = this.detailObj1.detailObj.title
      this.$refs.circulate.getCirculate(this.proInstId)
    },
    // 关闭传阅详情
    closeCirculate(val) {
      this.showCircu = false
    },

    //同意或已阅1-同意，2-已阅
    opinionType(type) {
      // console.log("this.paramObject: " + JSON.stringify(this.paramObject));
      this.$dialog.confirm({
        title: '系统提示',
        message: '确定要操作吗?',
      }).then(() => {
        // on confirm
        if (this.util.isNotEmpty(this.paramObject)) {
          if (type == 'addElements_yiyue') {//已阅
            if (this.util.isNotEmpty(this.paramObject)){
              if(this.paramObject.actDefId == "jldsh"){
                this.opiniontype = "jldps";
              } else if (this.paramObject.actDefId == "bmldsh") {
                this.opiniontype = "bmldyj";
              } else {
                this.opiniontype = "blbmyj";
              }
            }
            this.message = '已阅'
            this.saveopinion()
          } else if(type == 'addElements_yiyue_fs') {//已阅
            if (this.util.isNotEmpty(this.paramObject)){
              if(this.paramObject.actDefId == "jldsh"){
                this.opiniontype = "jldps";
              } else if (this.paramObject.actDefId == "bmldsh") {
                this.opiniontype = "blbmyj";
              } else {
                this.opiniontype = "blbmyj";
              }
            }
            this.message = '已阅'
            this.saveopinion()
          } else if(type == 'addElements_tongyi') {//同意
            if (this.util.isNotEmpty(this.paramObject)){
              if(this.paramObject.actDefId == "jldsh" || this.paramObject.actDefId == "jld"){
                this.opiniontype = "jldps";
              }
            }
            this.message = '同意'
            this.saveopinion()
          }
        }
      }).catch(() => {
        // on cancel
      });
    },
    //填写意见接口
    saveopinion(){
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/saveopinion`),
        method: 'post',
        params:{
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        },
        data: this.$http.adornData({
          'proInstId': this.paramObject.proInstId,//发文详情返回的proInstId
          'workItemId': this.paramObject.workitemId,//
          'actInstId': this.paramObject.actInstId,//
          'opiniontype':this.opiniontype,
          'opinion':this.message,
          'isApproval':'1',//核稿状态，默认传1
        })
      }).then(({data}) => {
        // console.log("填写意见返回：data-->: " + JSON.stringify(data));
        if(data.code==200){
          this.$toast('意见填写成功')
          this.refreshBtnGroup(true)
        }else{
          this.$toast(data.message+' code:'+data.code)
        }

      })
    },
    //作废
    cancelGwConfirm() {
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        this.cancelGw()
      }).catch(() => {
        // on cancel
      });
    },
    //作废公文
    cancelGw(){
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/abortApplictionController/abortApplication`),
        method: 'post',
        params:{
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          data:this.$http.adornData({
            'configId':this.paramObject.configId,
            'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
            'proInstId':this.paramObject.proInstId,
            'actInstId': this.paramObject.actInstId,//
            'workitemId':this.paramObject.workitemId,
            'gwId':this.fwId,
            'title':this.detailObj1.detailObj.title
          }),
        }
      }).then(({data}) => {
        if(data.code==200){
          this.$toast("操作成功")
          //作废后还需调另外两个接口
          this.canceGwUpdateDraftStatus()
          this.canceGwDeleteWordBiz()
          uni.redirectTo({
            url:'/pages/caac/send/signList'
          })
        }else{
          this.$toast(data.message+' code:'+data.code)
        }

      })

    },
    //作废-更新状态
    canceGwUpdateDraftStatus(){
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fw/updateDraftStatus`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'id':this.proInstId
        })
      }).then(({data}) => {
        //data: {"code":200,"data":{"userId":"3961"},"message":null}
        console.log("作废UpdateDraftStatus()--->data: " + JSON.stringify(data));
        // if(data.code==200){

        // }

      })

    },
    //作废-更新状态
    canceGwDeleteWordBiz(){
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fw/deleteWordBiz`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'fwId':this.fwId
        })
      }).then(({data}) => {
        //data: {"code":200,"data":{"userId":"3961"},"message":null}
        console.log("作废DeleteWordBiz()-->data: " + JSON.stringify(data));
        // if(data.code==200){
        // }

      })

    },
    //本单位会签完毕
    hqwbConfirm() {
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        // on confirm
//            this.jieshuGongWen()//本单位会签完毕和结束公文是同一个接口
        this.saveOpinionAndSendWithoutSelectUser('end')
      }).catch(() => {
        // on cancel
      });
    },
    //结束公文确认弹框
    endProcess() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '确定结束流程吗?',
      }).then(() => {
//            this.jieshuGongWen()//结束公文
        this.saveOpinionAndSendWithoutSelectUser('end')
      }).catch(() => {
        // on cancel
      });
    },
    //获取详情数据
    getCaacDetail(proInstId){
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/doc/fw/proInstId/`+proInstId),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        console.log("公文详情: " + JSON.stringify(data));
        if(data.code==200){
          //根据字典code获取字典
          this.detailObj1.detailObj =data.data
          this.generateParamObject.fwId = data.data.fwId
          this.generateParamObject.fwWord = data.data.fwWord
          this.generateParamObject.fwWordId = data.data.fwWordId
          this.fwId=data.data.fwId
          this.extendIdForRelate = data.data.extendIdForRelate
          this.getCaacBody(this.extendIdForRelate)//获取正文
          this.getCaacAttachment(this.extendIdForRelate)//获取附件
          this.getRelation(this.extendIdForRelate)//获取附加公文
          this.openwfneededdata(this.fwId,proInstId)
          this.parentdept(data.data.drafterDeptId)//获取拟制部门名称
          this.listbhfstrack(data.data.proInstId)//呈送领导和分送部门
          this.gwxqFlag = false //请求成功后置为false，防止tab切换重新获取数据
        }
      })
    },

    //获取正文数据
    getCaacBody(extendIdForRelate){
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/maintext/proInstId/`+extendIdForRelate),
        method: 'get',
        params: this.$http.adornParams({
          // 'extendIdForRelate': this.proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if(data.code==200){
          this.detailObj1.detailBody =data.data
        }
      })
    },

    //获取附件数据
    getCaacAttachment(extendIdForRelate){
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/attachmentupload/attachmentinfoOrderByNew`),
        method: 'get',
        params: this.$http.adornParams({
          'bizId': extendIdForRelate,
          'attachTypeId':'pageBody_uploadFile',
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        })
      }).then(({data}) => {
        if(data.code==200){
          this.detailObj1.detailAttachment =data.data
        }
      })
    },

    //获取意见
    getCaacOpinion(proInstId){
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/approvalwrite`),
        method: 'get',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if(data.code==200){
          if(data.data != null){
            this.detailObj1.opinion =data.data
          }
        }
      })
    },
    //获取附加公文
    getRelation(extendIdForRelate){
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/mhjComponent/relationfile/relation`),
        method: 'get',
        params: this.$http.adornParams({
          'docId': extendIdForRelate,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if(data.code==200){
          if(data.data != null){
            this.detailObj1.relation =data.data
          }
        }
      })
    },
    //获取流转过程
    getCaacDocProcess(proInstId){
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/listProInstIdOperationLogs`),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if(data.code==200){
          this.dataList.docProcess =data.data
          this.lzgcFlag = false
        }
      })
    },
    //获取子流转过程
    getListChildSubOperationLogs(proInstId){
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/listChildSubOperationLogs?systemKey=`+this.userInfo.systemKey+`&systemFlag=`+this.userInfo.systemFlag),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if(data.code==200){
          this.dataList.signProcess =data.data
        }
      })
    },


    //获取签批功能菜单optionBtn01
    openwfneededdata(fwId,proInstId){
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/comm/comm/openwfneededdata`),
        method: 'get',
        params: this.$http.adornParams({
          'id': fwId,//发文详情返回的fwId
          'proInstId': proInstId,//发文详情返回的proInstId
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if(data.code==200){
          this.detailObj1.optionBtn01 =data.data
          this.paramObject = data.data
          console.log("签批功能菜单optionBtn01: " + JSON.stringify(data.data));
          this.getRoleTypesAndActInst(data.data.configId,proInstId)
        }

      })
    },

    //获取签批功能菜单optionBtn02
    getRoleTypesAndActInst(configId,proInstId){
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/getRoleTypesAndActInst`),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,//发文详情返回的proInstId
          'configId': configId,//openwfneededdata()返回的configId
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if(data.code==200){
          this.detailObj1.optionBtn02 =data.data
          console.log("签批功能菜单optionBtn02: " + JSON.stringify(data.data));
          this.initActivity()

        }

      })
    },
    /**
     * 子页面流转后调用此方法刷新功能按钮
     * @param {Object} item Boolean值，为true 就刷新
     */
    refreshBtnGroup(item){
      // console.log("shuaxina "+item)
      this.getCaacDetail(this.proInstId)
      this.getCaacOpinion(this.proInstId)//重新获取意见
      this.quertcirs(this.proInstId)//传阅情况
      setTimeout(()=>{
        this.findfbdept(this.proInstId)//司局分办处室
      }, 500)
    },
    //获取签批功能菜单
    async initActivity(){
      // 获取要显示的按钮
      await this.getButtonsData(this.proInstId)
      const _this = this
      let option01 = this.detailObj1.optionBtn01
      let option02 = this.detailObj1.optionBtn02.actInstList[0] //TODO 次处返回了数组格式，需和pc端确认
      // console.log("option02===: " + JSON.stringify(option02));
      await this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/initActivity`),
        method: 'post',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'data':this.$http.adornData({
            'configId': option01.configId,//openwfneededdata()返回的configId
            'configCode': option01.configCode,
            'proDirId': option01.proDirId,
            'actDefId': option01.actDefId,
            'wfmRoleTypes': option02.wfmRoleTypes,
            'proInstId': option01.proInstId,
            'actInstId': option01.actInstId,
            'workitemId': option01.workitemId,
            'wfmInitPageType': 'running',
            'bizId': option01.bizId
          }),

        })
      }).then(({data}) => {
        console.log("data---->>: " + JSON.stringify(data));
        if(data.code==200){
          _this.detailObj1.optionBtn =data.data
          var operations = data.data.qualifiedOperations
          // console.log(operations);
          _this.barList = [] //重置为空
          if(operations != null && operations.length>0){
            for (let i = 0; i < operations.length; i++) {
              //修改公文要素
              if(operations[i].operation=='xggwys'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'xggwys',
                  icon:'static/imgs/icon/icon-xggwys.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-xggwys-active.png',
                    inactive: 'static/imgs/icon/icon-xggwys.png'
                  },
                  value:'修改公文要素',//operations[i].operationName, //拿到的值为填写公文要素
                  sort: 10
                })
              }
              //修改公文要素
              if(operations[i].operation=='addElements'){
                _this.barList.push({
                  name:'修改公文要素',//operations[i].operationName,
                  operation:'addElements',
                  icon:'static/imgs/icon/icon-xggwys.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-xggwys-active.png',
                    inactive: 'static/imgs/icon/icon-xggwys.png'
                  },
                  value:'修改公文要素',//operations[i].operationName, //拿到的值为填写公文要素
                  sort: 10
                })
              }
              //填写意见
              if(operations[i].operation=='addReviews'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'addReviews',
                  icon:'static/imgs/icon/icon-opinion.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-opinion-active.png',
                    inactive: 'static/imgs/icon/icon-opinion.png'
                  },
                  value:operations[i].operationName,
                  sort: 1
                })
              }
              //填写意见
              if(operations[i].operation=='addReviews_fk'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'addReviews_fk',
                  icon:'static/imgs/icon/icon-opinion.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-opinion-active.png',
                    inactive: 'static/imgs/icon/icon-opinion.png'
                  },
                  value:operations[i].operationName,
                  sort: 1
                })
              }

              //流转
              if(operations[i].operation=='generalMove'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'generalMove',
                  icon:'static/imgs/icon/icon-transfer.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-transfer-active.png',
                    inactive: 'static/imgs/icon/icon-transfer.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //流转
              if(operations[i].operation=='complete'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'complete',
                  icon:'static/imgs/icon/icon-transfer.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-transfer-active.png',
                    inactive: 'static/imgs/icon/icon-transfer.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //结束公文
              if(operations[i].operation =='js'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'js',
                  icon:'static/imgs/icon/icon-finished.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-finished-active.png',
                    inactive: 'static/imgs/icon/icon-finished.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //办毕
              if(operations[i].operation =='endProcess'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'endProcess',
                  icon:'static/imgs/icon/icon-finished.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-finished-active.png',
                    inactive: 'static/imgs/icon/icon-finished.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }

              //传阅
              if(operations[i].operation =='circulate'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'circulate',
                  icon:'static/imgs/icon/icon-yy.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-yy-active.png',
                    inactive: 'static/imgs/icon/icon-yy.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }

              //分办管理
              if(operations[i].operation =='fbgl'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'fbgl',
                  icon:'static/imgs/icon/icon-handover.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-handover-active.png',
                    inactive: 'static/imgs/icon/icon-handover.png'
                  },
                  value:operations[i].operationName,
                })
              }
              //分办管理
              if(operations[i].operation =='sendFb'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'fbgl',
                  icon:'static/imgs/icon/icon-handover.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-handover-active.png',
                    inactive: 'static/imgs/icon/icon-handover.png'
                  },
                  value:operations[i].operationName,
                })
              }
              //分送管理
              if(operations[i].operation =='distribute'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'distribute',
                  icon:'static/imgs/icon/icon-handover.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-handover-active.png',
                    inactive: 'static/imgs/icon/icon-handover.png'
                  },
                  value:operations[i].operationName,
                })
              }
              //会签管理
              if(operations[i].operation =='huiqianManagement'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'huiqianManagement',
                  icon:'static/imgs/icon/icon-sign.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-sign-active.png',
                    inactive: 'static/imgs/icon/icon-sign.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //退公文秘书
              if(operations[i].operation ==='goOutToSms' || operations[i].operation ==='goOutToMszz' || operations[i].operation ==='liuzhuanTuimishu'
                || operations[i].operation ==='szsliuzhuanTuimishu'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:operations[i].operation,
                  icon:'static/imgs/icon/icon-tuigwms.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-tuigwms-active.png',
                    inactive: 'static/imgs/icon/icon-tuigwms.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //退公文秘书
              if(operations[i].operation =='tgwms'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'tgwms',
                  icon:'static/imgs/icon/icon-tuigwms.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-tuigwms-active.png',
                    inactive: 'static/imgs/icon/icon-tuigwms.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //退公文秘书
              if(operations[i].operation =='sendback'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'sendback',
                  icon:'static/imgs/icon/icon-tuigwms.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-tuigwms-active.png',
                    inactive: 'static/imgs/icon/icon-tuigwms.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //签发
              if(operations[i].operation =='review_QianFa'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'review_QianFa',
                  icon:'static/imgs/icon/icon-qianfa.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-qianfa-active.png',
                    inactive: 'static/imgs/icon/icon-qianfa.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //作废
              if(operations[i].operation =='cancelGw'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'cancelGw',
                  icon:'static/imgs/icon/icon-invalid.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-invalid-active.png',
                    inactive: 'static/imgs/icon/icon-invalid.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //作废
              if(operations[i].operation =='delForm'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'delForm',
                  icon:'static/imgs/icon/icon-invalid.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-invalid-active.png',
                    inactive: 'static/imgs/icon/icon-invalid.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //同意
              if(operations[i].operation =='addElements_tongyi'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'addElements_tongyi',
                  icon:'static/imgs/icon/icon-agree.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-agree-active.png',
                    inactive: 'static/imgs/icon/icon-agree.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //已阅
              if(operations[i].operation =='addElements_yiyue_fs'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'addElements_yiyue_fs',
                  icon:'static/imgs/icon/icon-yy.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-yy-active.png',
                    inactive: 'static/imgs/icon/icon-yy.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //已阅
              if(operations[i].operation =='addElements_yiyue'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'addElements_yiyue',
                  icon:'static/imgs/icon/icon-yy.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-yy-active.png',
                    inactive: 'static/imgs/icon/icon-yy.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //本单位会签完毕
              if(operations[i].operation =='hqwb'){
                _this.barList.push({
                  name:operations[i].operationName,
                  operation:'hqwb',
                  icon:'static/imgs/icon/icon-agree.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab:{
                    active: 'static/imgs/icon/icon-agree-active.png',
                    inactive: 'static/imgs/icon/icon-agree.png'
                  },
                  value:operations[i].operationName,
                  sort: operations[i].sort
                })
              }
              //清除意见
              if (operations[i].operation == 'deleteOpinion') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'deleteOpinion',
                  icon: 'static/imgs/icon/icon-invalid.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-invalid-active.png',
                    inactive: 'static/imgs/icon/icon-invalid.png'
                  },
                  value: operations[i].operationName,
                  sort: operations[i].sort
                })
              }


            }
            // 功能按钮筛选
            if(this.util.isNotEmpty(this.buttonArr)){
              let newBarList = []
              this.buttonArr.filter((b, index) => this.buttonArr.indexOf(b) === index).forEach((item)=>{
                let arr = this.barList.filter(t => t.operation == item)
                if(arr != null && arr.length > 0) {
                  newBarList.push(arr[0])
                }
              })
              this.barList = newBarList
            }else{
              this.barList=[]//如果获取到的按钮为空，则置空
            }
            //大于三个添加更多按钮,第四个按钮为更多操作
            if(_this.barList.length>3){
              _this.barList.sort((a, b) => a.sort - b.sort)
              var more ={
                name:'更多',
                operation:'more',
                icon:'static/imgs/icon/icon-more.png',
                iconTab:{
                  active: 'static/imgs/icon/icon-more-active.png',
                  inactive: 'static/imgs/icon/icon-more.png',
                },
                value:'更多操作',
              }
              _this.barList.splice(3, 0, more);
            }
          }
        }else{
          console.log("出错了: " + JSON.stringify(data));
        }
      })
      await this.showDeleteOpinionBtn()//判断是否显示清除意见按钮
    },
    //办结并退秘书
    endAndTuimsConfirm() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '确认要结束公文吗?',
      }).then(() => {
        this.saveOpinionAndSendWithoutSelectUser('end')
      }).catch(() => {

      });
    },
    //退公文秘书
    tuiGwmsConfirm(type){
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        if (type === 'goOutToSms') {//退司秘书
          this.saveOpinionAndSendWithoutSelectUser('sms')
        } else if (type === 'goOutToMszz') {//退局秘书
          this.saveOpinionAndSendWithoutSelectUser('mszz')
        }else if ( type === 'liuzhuanTuimishu'){
          this.liuzhuanTuimishu()
        }else if (type === 'szsliuzhuanTuimishu'){
          this.szsliuzhuanTuimishu()
        }
      }).catch(() => {
      });
    },
    szsliuzhuanTuimishu(){
      let szsMs
      const deptId = this.userInfo.mainDept.deptId
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/sd/findszsms`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'deptId':deptId
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (this.util.isNotEmpty(data.data) && this.util.isNotEmpty(data.data.user)) {
            szsMs = data.data.user.userId;
            this.sendWithoutSelectUserSzs(szsMs);
          } else {
            this.$toast('该领导未配置秘书，需配置！')
          }
        } else {
          this.$toast(data.message)
        }

      })
    },
    liuzhuanTuimishu(){
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/MhjApplicationController/getJldMsRelate`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        })
      }).then(({data}) => {
        let msId = ''
        if (data.code == 200) {
          if (this.util.isNotEmpty(data.data)) {
            data.data.forEach((item) => {
              if (this.userInfo.userId == item.ldId) {
                msId = item.msId
              }
              if(this.util.isEmpty(msId)){
                this.$toast('该领导未配置秘书，需配置！')
              }else{
                this.sendWithoutSelectUserJuld(msId)
              }
            })
          } else {
            this.$toast('该领导未配置秘书，需配置！')
          }
        } else {
          this.$toast("获取秘书失败,code:"+data.code)
        }

      })
    },
    /**
     * 秘书id
     * @param msId
     */
    sendWithoutSelectUserJuld(msId){
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/listNextActivities`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'data': this.$http.adornData({
            wfmData: {
              'configId': this.paramObject.configId,
              'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': this.paramObject.actDefId,//
              'actInstId': this.paramObject.actInstId,//
              'workitemId': this.paramObject.workitemId,
              'wfmInitPageType': 'running'
            }
          })
        }
      }).then(({data}) => {
        if (this.util.isNotEmpty(data.data.nextActDefIds)){
          let nextActDefIds = data.data.nextActDefIds
          let nextActivity = {}
          let currentActDefId = this.paramObject.actDefId
          for(let i = 0; i < nextActDefIds.length; i++){
            if ( ("jzbgs" === nextActDefIds[i].actDefId && currentActDefId.indexOf("jld")> -1) || ("jzbgszz" === nextActDefIds[i].actDefId && currentActDefId.indexOf("jld")> -1)){
              nextActivity = nextActDefIds[i];
            }
          }
          nextActivity.participants = "user:" + msId
          let nextActivities = []
          nextActivities.push(nextActivity)
          //退公文秘书
          this.$httploading({
            url: this.$http.adornUrl(`/caac/wfm/ApplicationController/completeWorkitem`),
            method: 'post',
            params: {
              'systemKey': this.userInfo.systemKey,//固定值
              'systemFlag': this.userInfo.systemFlag,//固定值
              'data': this.$http.adornData({
                'bhForm': this.detailObj1.detailObj,//详情
                'wfmData': {
                  'configId': this.paramObject.configId,
                  'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
                  'actDefId': this.paramObject.actDefId,//
                  'proInstId': this.paramObject.proInstId,
                  'actInstId': this.paramObject.actInstId,//
                  'workitemId': this.paramObject.workitemId,
                  'nextActivities': nextActivities
                },
              })
            }
          }).then(({data}) => {
            if (data.code == 200) {
              if(data.data){
                if(data.data.wfmData.isClosePage){
                  this.$toast('操作成功！')
                }else{
                  this.$toast(data.data.wfmData.message)
                }
                // 发送通知
                let messageUserIds = msId;
                let linkUrl = this.configUtil.baseUrl + this.configUtil.basePath + "/#/pages/caac/jnbh/index?proInstId=" + this.paramObject.proInstId
                this.lx.sendMessage(this.cache.get("appType"), messageUserIds,
                    this.detailObject.title, "局内便函", linkUrl)
                uni.redirectTo({
                  url: '/pages/caac/send/signList'
                })
              }else{
                this.$toast("提交后返回数据为空，resultData=" + data.data)
              }
            } else {
              this.$toast(data.message + ' code:' + data.code)
            }

          })
        }else{
          this.$toast("操作失败，获取流程节点信息为空")
        }

      })
    },
    sendWithoutSelectUserSzs(msId){
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/listNextActivities`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'data': this.$http.adornData({
            'wfmData': {
              'configId': this.paramObject.configId,
              'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': this.paramObject.actDefId,//
              'actInstId': this.paramObject.actInstId,//
              'workitemId': this.paramObject.workitemId,
              'wfmInitPageType': 'running'
            }
          })
        }
      }).then(({data}) => {
        if (this.util.isNotEmpty(data.data.nextActDefIds)){
          let nextActivity = {};
          let nextActivities = [];
          nextActivities.push(nextActivity);
          this.$httploading({
            url: this.$http.adornUrl(`/caac/wfm/ApplicationController/gotoActivity`),
            method: 'post',
            params: {
              'systemKey': this.userInfo.systemKey,//固定值
              'systemFlag': this.userInfo.systemFlag,//固定值
              data: this.$http.adornData({
                wfmData: {
                  'configId': this.paramObject.configId,
                  'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
                  'actDefId': this.paramObject.actDefId,//
                  'proInstId': this.paramObject.proInstId,
                  'actInstId': this.paramObject.actInstId,//
                  'workitemId': this.paramObject.workitemId,
                  'nextActivities': nextActivity,
                  'formData': {
                    bhForm: this.detailObj1.detailObj,//详情
                  },
                  "gotoResourceIds": "user:" + msId,
                  'gotoActDefId': 'otherTask'
                },
              })
            }
          }).then(({data}) => {
            if (data.code == 200) {
              this.$toast("操作成功")
              // 发送通知
              let messageUserIds = msId;
              let linkUrl = this.configUtil.baseUrl + this.configUtil.basePath + "/#/pages/caac/jnbh/index?proInstId=" + this.paramObject.proInstId
              this.lx.sendMessage(this.cache.get("appType"), messageUserIds,
                  this.detailObject.title, "局内便函", linkUrl)
              uni.redirectTo({
                url: '/pages/caac/send/signList'
              })
            } else {
              this.$toast(data.message + ' code:' + data.code)
            }

          })
        }else {
          this.$toast("操作失败，获取流程节点信息为空");
        }
      })
    },
    //获取流转范围
    saveOpinionAndSendWithoutSelectUser(goOutType) {
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/listNextActivities`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'data': this.$http.adornData({
            wfmData: {
              'configId': this.paramObject.configId,
              'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': this.paramObject.actDefId,//
              'actInstId': this.paramObject.actInstId,//
              'workitemId': this.paramObject.workitemId,
              'wfmInitPageType': 'running'
            }
          })
        }
      }).then(({data}) => {
        if (data.code == 200) {
          let actType = "";
          let nextActDefIds = data.data.nextActDefIds
          if (nextActDefIds) {
            if (goOutType) {
              actType = goOutType
            }
            for (let i = 0; i < nextActDefIds.length; i++) {
              let nextActivity = nextActDefIds[i]
              if (nextActivity.actType === actType || nextActivity.actDefId === actType) {
                nextActivity.participants = "user:" + this.userInfo.userId
                if (this.util.isNotEmpty(goOutType) && goOutType === 'sms') {
                  //获取司秘书
                  this.$http({
                    url: this.$http.adornUrl(`/caac/oa/doc/sd/csmsuser`),
                    method: 'get',
                    params: this.$http.adornParams({
                      'systemKey': this.userInfo.systemKey,//固定值
                      'systemFlag': this.userInfo.systemFlag,//固定值
                    })
                  }).then(({data}) => {
                    // {"code":200,"data":{"userId":"3961"},"message":null}
                    if (data.code == 200) {
                      if (this.util.isNotEmpty(data.data)) {
                        nextActivity.participants = data.data.userId
                        let nextActivities = []
                        nextActivities.push(nextActivity)
                        //退公文秘书
                        this.$httploading({
                          url: this.$http.adornUrl(`/caac/wfm/ApplicationController/completeWorkitem`),
                          method: 'post',
                          params: {
                            'systemKey': this.userInfo.systemKey,//固定值
                            'systemFlag': this.userInfo.systemFlag,//固定值
                            'data': this.$http.adornData({
                              'bhForm': this.detailObj1.detailObj,//详情
                              'wfmData': {
                                'configId': this.paramObject.configId,
                                'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
                                'actDefId': this.paramObject.actDefId,//
                                'proInstId': this.paramObject.proInstId,
                                'actInstId': this.paramObject.actInstId,//
                                'workitemId': this.paramObject.workitemId,
                                'nextActivities': nextActivities
                              },
                            })
                          }
                        }).then(({data}) => {
                          if (data.code == 200) {
                            if(data.data){
                              if(data.data.wfmData.isClosePage){
                                this.$toast('公文已退回给公文秘书！')
                              }else{
                                this.$toast(data.data.wfmData.message)
                              }
                              // 发送通知
                              let messageUserIds = data.data.userId;
                              let linkUrl = this.configUtil.baseUrl + this.configUtil.basePath + "/#/pages/caac/jnbh/index?proInstId=" + this.paramObject.proInstId
                              this.lx.sendMessage(this.cache.get("appType"), messageUserIds,
                                  this.detailObject.title, "局内便函", linkUrl)
                              uni.redirectTo({
                                url: '/pages/caac/send/signList'
                              })
                            }else{
                              this.$toast("提交后返回数据为空，resultData=" + data.data)
                            }
                          } else {
                            this.$toast(data.message + ' code:' + data.code)
                          }
                        })
                      } else {
                        this.$toast('该领导未配置秘书，需配置！')
                      }
                    } else {
                      this.$toast(data.message)
                    }

                  })
                }else{
                  let nextActivities = []
                  nextActivities.push(nextActivity)
                  //退公文秘书
                  this.$httploading({
                    url: this.$http.adornUrl(`/caac/wfm/ApplicationController/completeWorkitem`),
                    method: 'post',
                    params: {
                      'systemKey': this.userInfo.systemKey,//固定值
                      'systemFlag': this.userInfo.systemFlag,//固定值
                      'data': this.$http.adornData({
                        'bhForm': this.detailObj1.detailObj,//详情
                        'wfmData': {
                          'configId': this.paramObject.configId,
                          'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
                          'actDefId': this.paramObject.actDefId,//
                          'proInstId': this.paramObject.proInstId,
                          'actInstId': this.paramObject.actInstId,//
                          'workitemId': this.paramObject.workitemId,
                          'nextActivities': nextActivities
                        },
                      })
                    }
                  }).then(({data}) => {
                    if (data.code == 200) {
                      if(data.data){
                        if(data.data.wfmData.isClosePage){
                          this.$toast('公文已退回给公文秘书！')
                        }else{
                          this.$toast(data.data.wfmData.message)
                        }
                        // 发送通知
                        let messageUserIds = this.userInfo.userId;
                        let linkUrl = this.configUtil.baseUrl + this.configUtil.basePath + "/#/pages/caac/jnbh/index?proInstId=" + this.paramObject.proInstId
                        this.lx.sendMessage(this.cache.get("appType"), messageUserIds,
                            this.detailObject.title, "局内便函", linkUrl)
                        uni.redirectTo({
                          url: '/pages/caac/send/signList'
                        })
                      }else{
                        this.$toast("提交后返回数据为空，resultData=" + data.data)
                      }
                    } else {
                      this.$toast(data.message + ' code:' + data.code)
                    }

                  })
                }

              }
            }
          } else {
            this.$toast("操作失败，获取流程节点信息为空")
          }
        }

      })
    },
    //退回便函拟稿人
    sendBackConfirm(){
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      })
          .then(() => {
            // on confirm
            this.listCanSendbackActivities()
          })
          .catch(() => {
          });
    },
    listCanSendbackActivities(){
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/listCanSendbackActivities`),
        method: 'post',
        params: {
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'data':this.$http.adornData({
            'wfmData': {
              'proInstId': this.paramObject.proInstId,
              'actInstId': this.paramObject.actInstId,//
            },
            'wfmActivityConfig': {
              'sendbackType': 'input'
            }
          })
        },

      }).then(({data}) => {
        if (data.code == 200) {
          // console.log("listCanSendbackActivities-->>: " + JSON.stringify(data));
          if(this.util.isNotEmpty(data.data)){
            this.toActInstId = data.data[0].id//
            this.sendbackActivity()
          }else{
            this.$toast("获取函拟稿人信息失败！")
          }
        }
      })
    },
    //退回便函拟稿人 先调上面的接口(listCanSendbackActivities)
    sendbackActivity(){
      this.$httploading({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/sendbackActivity`),
        method: 'post',
        params:{
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          data:this.$http.adornData({
            wfmData:{
              'configId':this.paramObject.configId,
              'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': this.paramObject.actDefId,//
              'proInstId':this.paramObject.proInstId,
              'actInstId': this.paramObject.actInstId,//
              'workitemId':this.paramObject.workitemId,
              'sendbackType':'input',
              'toActInstId':this.toActInstId,
            },
            'bhForm':this.detailObj1.detailObj,//详情
          })
        }
      }).then(({data}) => {
        // console.log("退回便函拟稿人返回结果-->>: " + JSON.stringify(data));
        if(data.code==200){
          this.$toast("操作成功")
          uni.redirectTo({
            url:'/pages/caac/send/signList'
          })
        }else{
          this.$toast(data.message+' code:'+data.code)
        }

      })
    },


    //获取拟制部门-详情drafterDeptId
    parentdept(drafterDeptId) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/jbh/parentdept`),
        method: 'get',
        params: {
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'deptId':  drafterDeptId
        }
      }).then(({data}) => {
        if (data.code == 200) {
          this.otherDetail.nizhiDeptName = data.data
        }
      })
    },
    //获取呈送领导-详情proInstId
    listbhfstrack(proInstId) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/jbh/listbhfstrack`),
        method: 'get',
        params: {
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'proInstId':  proInstId
        }
      }).then(({data}) => {
        if (data.code == 200) {
          this.otherDetail.fsDataList = data.data
        }
      })
    },
    //获取司局分办处室-列表proInstId
    findfbdept(proInstId) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/fb/findfbdept`),
        method: 'get',
        params: {
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'proInstId':  proInstId
        }
      }).then(({data}) => {
        //{"code":200,"data":{"runningNum":0,"deptIds":"","depts":""},"message":null}
        if (data.code == 200) {
          this.otherDetail.fbDeptList=[]
          data.data.deptIds.split(',').forEach((item,index)=>{
            this.otherDetail.fbDeptList.push({"deptId":item,"deptName":data.data.depts.split('、')[index]})
          })
        }
      })
    },
    //传阅情况-列表proInstId
    quertcirs(proInstId) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/circulatecontroller/quertcirs`),
        method: 'get',
        params: {
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'proInstId':  proInstId,
          'senderId':this.cache.get('userInfo').userId
        }
      }).then(({data}) => {
        if (data.code == 200) {
          this.dataList.quertcirsProcess = data.data
          //根据receiverDeptName去重
          const res = new Map()
          this.otherDetail.chuanYueList = data.data.filter((t)=>!res.has(t['receiverDeptName']) && res.set(t['receiverDeptName'],1))
        }
      })
    },
    //判断是否显示清除意见按钮
    async showDeleteOpinionBtn(){
      await this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/findmyopinion`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'proInstId':this.proInstId,
          'workItemId':this.paramObject.workitemId,
          'approver':this.userInfo.userId
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (this.util.isNotEmpty(data.data)) {
            this.opinionId = data.data.id //要删除的意见id
          }else{
            this.opinionId = ''
            //如果意见为null,则不显示清除意见按钮
            this.barList = this.barList.filter(t => t.operation != 'deleteOpinion' && t.operation != 'more')
            //大于三个添加更多按钮,第四个按钮为更多操作
            if (this.barList.length > 3) {
              this.barList.sort((a, b) => a.sort - b.sort)
              let more = {
                name: '更多',
                operation: 'more',
                icon: 'static/imgs/icon/icon-more.png',
                iconTab: {
                  active: 'static/imgs/icon/icon-more-active.png',
                  inactive: 'static/imgs/icon/icon-more.png',
                },
                value: '更多操作',
              }
              this.barList.splice(3, 0, more);
            }
          }
        } else {
          console.log(data.message)
        }

      })

    },
    //清除意见
    deleteOpinionConfirm(){
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        this.deleteOpinion()//删除意见
      }).catch(() => {
      });
    },
    //删除意见
    deleteOpinion() {
      if (this.util.isNotEmpty(this.opinionId)) {
        this.$http({
          url: this.$http.adornUrl(`/caac/oa/component/approval`),
          method: 'delete',
          params: this.$http.adornParams({
            'systemKey': this.userInfo.systemKey,//固定值
            'systemFlag': this.userInfo.systemFlag,//固定值
            'opinionId': this.opinionId
          })
        }).then(({data}) => {
          if (data.code == 200) {
            this.$toast("删除意见成功")
            this.refreshBtnGroup('')
          } else {
            this.$toast(data.message)
          }
        })
      }else{
        this.$toast('当前没有可删除的意见!')
      }
    }


  },
};
</script>

<style scoped>

</style>
